package com.huonan.component.sftp;

import cn.hutool.extra.ftp.FtpConfig;
import cn.hutool.extra.ssh.Sftp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Component
public class SftpComment {
    private  Sftp getInstance() {
        FtpConfig ftpConfig = new FtpConfig();
        ftpConfig.setHost("dts-nb.mininglamp.com")
                .setPort(2222)
                .setUser("social_cd_test")
                .setPassword("A2i7p+62R")
                .setCharset(Charset.defaultCharset());
        return new Sftp(ftpConfig);
    }

    public  List<String> lsFiles(String srcPath) {
        try (Sftp sftp = getInstance();) {
            List<String> list = sftp.lsFiles(srcPath);
            return list.stream().map(f -> srcPath + "/" + f).collect(Collectors.toList());
        }
    }
    public  List<String> lsDirs(String srcPath) {
        try (Sftp sftp = getInstance();) {
            List<String> list = sftp.lsDirs(srcPath);
            return list.stream().map(f -> srcPath + "/" + f).collect(Collectors.toList());
        }
    }
}
